Skip to content

Add exercises to every chapter, expand core chapters, fix technical errors - #1

Merged
dnakhoa merged 10 commits into
mainfrom
claude/course-improvements-pyoyiu
Nov 6, 2026
Merged

dnakhoa merged 10 commits into
mainfrom
claude/course-improvements-pyoyiu

Conversation

@dnakhoa

@dnakhoa dnakhoa commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Summary

Exercises everywhere. Every one of the 31 chapters now ends with a graded exercise set (★ check, ★★ apply, ★★★ stretch). There are 225 exercises in total, each with a folded worked solution and, for the harder ones, a hint. Python in solutions was run with asserts. CI now checks that each chapter has an Exercises section, that exercises are numbered in order, and that the <details> markup has the blank lines mdBook needs.

Expanded chapters

  • Ch 11 Graphs, rewritten: CSR and edge lists, BFS paths, three-colour cycle detection, bipartiteness, Kahn and DFS topological sort, Kosaraju SCCs, cut property, Bellman-Ford, a Dijkstra trace and diagram, and a shortest-path selection table. Fixes broken Prim/Kruskal code and a wrong example diagram.
  • Ch 3 Arrays: binary search (half-open invariant, lower/upper bound, overflow bug), search on the answer, two pointers, sliding windows, prefix sums, cache behaviour.
  • Ch 4 Linked lists: reversal, fast/slow pointers, Floyd's cycle detection with proof and diagram, merging, merge sort.
  • Ch 6 Trees: iterative traversals, the recursive tree-function pattern, rebuilding from traversals, serialization.
  • Ch 7 BST (was the thinnest chapter): deletion trace, random-BST height, successor/predecessor with diagram, range queries, validation, order statistics, history.
  • Ch 9 Heaps: indexed heap with decrease-key, d-ary heaps, top-k, k-way merge, running median, and an index-mapping diagram.
  • Ch 10 B-trees: deletion (previously missing entirely) with diagram, a complete tested implementation, the height bound, B+ range scans, bulk loading.
  • Ch 29 System design: power of two choices, with seeded simulations; cache eviction policies (LFU, CLOCK, ARC, W-TinyLFU), with a hit-rate simulation.
  • Volume overviews for I-III were rewritten as study guides covering prerequisites, what each chapter teaches, and a suggested route.

Technical fixes found along the way (details in each commit message):

  • Code: link-cut tree, wavelet tree and sparse table (Ch 23); red-black fix-up loop that never ran (Ch 8); pairing heap (Ch 9); B-tree insert losing the root (Ch 10); OR-Set tombstones and version-vector concurrency (Ch 27); Space-Saving eviction (Ch 28); LFU eviction (Ch 29); HNSW level sampling (Ch 30).
  • Facts: succinct-space definitions (Ch 24), struct sizes and made-up anecdotes (Ch 2), shunting-yard associativity (Ch 5), Cayley's formula (Ch 6), Dynamo quorum rule and Spanner commit wait (Ch 31).
  • Styling: custom CSS used rem against mdBook's 62.5% root size, so chapter footers and figure captions were rendering at 9-11px.

Verification

  • python3 scripts/check_book.py passes: all Python blocks parse, and every link and exercise block is well formed.
  • mdbook build emits no warnings.
  • New diagrams were checked in light and dark themes.

Generated by Claude Code

claude added 10 commits November 6, 2026 12:10
…rcises

The old chapter's Prim's code unpacked neighbour tuples in the wrong
order, Kruskal referenced undefined names, the example diagram did not
match its edge set, and topological sort silently returned partial
orders on cyclic input. The chapter now covers edge lists and CSR,
BFS path reconstruction, three-colour cycle detection, bipartiteness,
Kahn and DFS topological sort, Kosaraju SCCs, the cut property,
Bellman-Ford, a worked Dijkstra trace with why negative edges break it,
a shortest-path selection table, historical context, and 8 exercises.
Every Python block runs, and the algorithms were cross-checked against
each other on random graphs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Each chapter now ends with 5-8 exercises (traces, proofs, find-the-bug,
implementations, design questions) graded by difficulty, with folded
hints and worked solutions. Python in solutions was run with asserts.

Writing the exercises surfaced real errors, fixed here, including:
broken link-cut tree, wavelet tree kth and sparse table code (Ch 23);
wrong succinct-space definitions and broken rank/find_close (Ch 24);
red-black fix-up loop that never ran, wrong balance-factor signs (Ch 8);
corrupt pairing heap and binomial-heap figures (Ch 9); B-tree insert
losing the root (Ch 10); wrong struct size and invented overflow
anecdotes (Ch 2); shunting-yard associativity (Ch 5); Cayley's formula
(Ch 6); vEB layout example (Ch 16, 24); path-copying example and figure
(Ch 17); OR-Set tombstones, version-vector concurrency, Paxos phases and
quorum tolerance (Ch 27); BGP and TCAM descriptions and Space-Saving
eviction (Ch 28); HNSW level sampling and shard remapping (Ch 30);
Dynamo quorum condition and Spanner commit wait (Ch 31).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
check_book.py now requires an Exercises section in every chapter, checks
exercise numbering, and checks the blank lines mdBook needs inside
<details> blocks. Hints and solutions get a folded callout style and are
expanded automatically when printing. Custom CSS font sizes switch from
rem to em: mdBook's root font size is 62.5%, so the 'Where this connects'
footer and figure captions were rendering at 9-11px. README, landing
page and CONTRIBUTING describe the exercises.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
The Volume I-III overview pages were bare link lists (Volume II's was 25
words). Each now says what the volume is about, what to know before
starting, what each chapter lets you do, and a suggested reading route.
Chapter 11 gains a figure of the Dijkstra worked example with its
shortest-path tree. Also removes a stray em-dash from Volume IV's note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Adds decrease-key via an indexed min-heap (with the lazy-deletion
alternative used in Chapter 11), d-ary heaps and why d = 4 often wins,
top-k, k-way merge and running median, Python heapq idioms, a heap sort
trace, an array-to-tree index diagram and three exercises. Fixes the
PriorityQueue example, which called undefined sift methods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Chapter 3 had no searching at all. Adds binary search with a half-open
invariant (lower/upper bound, the midpoint overflow bug), binary search
on the answer, two pointers, sliding windows, prefix sums as the inverse
of difference arrays (including 2-D), and why arrays win on real caches.

Chapter 4 adds in-place reversal, fast/slow pointers with a full
argument for Floyd's cycle-start property (plus a diagram), merging with
a dummy head, and merge sort on lists. Fixes a wrong claim that Lua
tables are unrolled lists.

Both chapters get three new exercises and added historical notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Chapter 7 was the thinnest chapter in the book. Adds a worked deletion
trace, the expected height of random BSTs and the link to quicksort,
successor/predecessor (with a diagram), floor/ceiling and range queries,
BST validation (and the classic wrong version), order statistics via
subtree sizes, and a historical context section.

Chapter 6 adds iterative traversals with an explicit stack, the
recursive tree-function pattern (height, size and diameter in one pass),
rebuilding a tree from traversals and why preorder plus postorder is
ambiguous, and serialization.

Both chapters get new exercises; overlapping old exercises were reworked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
The chapter had no deletion at all. Adds single-pass top-down deletion
covering every case (borrow, merge, predecessor/successor replacement,
root shrink) with a worked example and a borrow-vs-merge diagram, what
real databases do instead, a complete tested B-tree (search, insert,
delete) with an invariant-checking random test, the height bound with a
billion-key example, B+ tree range scans over leaf links, bulk loading,
and two exercises.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Adds power-of-two-choices load balancing with seeded simulations of max
load and of herding under stale load data, and where NGINX, HAProxy and
Envoy use it. Adds eviction policies as data structures: O(1) LFU and
LFU-DA, CLOCK, ARC and W-TinyLFU, with a comparison table and a seeded
hit-rate simulation. Replaces the old LFU-D example, whose eviction
could empty the whole cache and which did not implement dynamic aging.
Three new exercises.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ga8rBjM4kRZRhxKLznhSca
@dnakhoa
dnakhoa merged commit af279c2 into main Nov 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants